package com.yzr.demo02;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Test01 {
    volatile int a = 1;
    volatile int b = 1;
    public void add(){
        log.info("add start");
        for (int i = 0; i < 10000; i++) {
            a++;
            b++;
        }
        log.info("add done");
    }

    public void compare(){
        log.info("compare start");
        for (int i = 0; i < 10000; i++) {
            //a始终等于b吗？
            if (a < b){
                log.info("a:{},b:{},{}",a,b,a>b);
                //最后的a>b应该殇false吗
            }
        }
        log.info("compare done");
    }

    public static void main(String[] args) {
        Test01 t1 = new Test01();
            new Thread(()->t1.add()).start();
            new Thread(()->t1.compare()).start();
    }
}
